package cn.itcast.web.exceptions;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统一异常处理
 */
@Component
public class CustomExceptionResolver implements HandlerExceptionResolver {
   /**
    *  1.跳转到美化了的错误页面
    *  2.携带错误信息
    */
   public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
      // 打印异常信息
      // 打印异常
      ex.printStackTrace();
      // 返回
      ModelAndView mv = new ModelAndView();
      mv.setViewName("error");
      return mv;
   }
}